package com.chujian.Utils;

import java.lang.reflect.Type;
import java.util.List;

import com.chujian.model.Book;
import com.chujian.model.Food;
import com.chujian.model.FoodList;
import com.chujian.model.IncomeMsg;
import com.chujian.model.NotificationBean;
import com.chujian.model.Order;
import com.chujian.model.Table;
import com.chujian.model.User;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
 * json数据解析的类
 * @author cc
 *
 */
public class JsonUtil {
/**
 * 对json串进行解析，返回order对象
 * @param jsondata
 * @return Order
 */
	public static Order OrderFromJson(String jsondata) {

		Type orderType = new TypeToken<Order>() {}.getType();
		Gson gson = new Gson();
		Order order = gson.fromJson(jsondata, orderType);
		return order;

	}
	public static List<Order> OrderListFromJson(String jsondata){
		Type type=new TypeToken<List<Order>>(){}.getType();
		Gson gson=new Gson();
		List<Order>list=gson.fromJson(jsondata, type);
		return list;
	}
	/**
	 * 对json串进行解析
	 * @param jsondata
	 * @return User
	 */
	public static User UserFromJson(String jsondata){
		
		Type userType=new TypeToken<User>(){}.getType();
		Gson gson=new Gson();
		User user=gson.fromJson(jsondata, userType);
		return user;
	}
	/**
	 * 将json串解析为字符串链表
	 * @param jsondata
	 * @return
	 */
	public static List<String> StringArrayFromJson(String jsondata){
		Type userType=new TypeToken<List<String>>(){}.getType();
		Gson gson=new Gson();
		List<String>list=gson.fromJson(jsondata, userType);
		return list;
	}
	/**
	 * 将json串解析为Food链表
	 * @param jsondata
	 * @return
	 */
	public static List<Food> ListFoodFromJson(String jsondata){
		Type type=new TypeToken<List<Food>>(){}.getType();
		Gson gson=new Gson();
		List<Food>list=gson.fromJson(jsondata, type);
		return list;
	}
	/**
	 * 将json串解析为Table链表
	 * @param jsondata
	 * @return
	 */
	public static List<Table> TableListFromJson(String jsondata){
		Type type=new TypeToken<List<Table>>(){}.getType();
		Gson gson=new Gson();
		List<Table>list=gson.fromJson(jsondata, type);
		return list;
	}
	public static Table TableFromJson(String jsondata){
		Type type=new TypeToken<Table>(){}.getType();
		Gson gson=new Gson();
		Table table=gson.fromJson(jsondata, type);
		return table;
	}
	public static Food FoodFromJson(String jsondata){
		Type type=new TypeToken<Food>(){}.getType();
		Gson gson=new Gson();
		Food food=gson.fromJson(jsondata, type);
		return food;
	}
	
	/*public static List<CurrentOrderBean> CuOrderBeanFromJson(String jsondata){
		Type type=new TypeToken<List<CurrentOrderBean>>(){}.getType();
		Gson gson=new Gson();
		List<CurrentOrderBean>list=gson.fromJson(jsondata, type);
		return list;
		
	}*/
	public static List<FoodList> FoodListFromJson(String jsondata){
		Type type=new TypeToken<List<FoodList>>(){}.getType();
		Gson gson=new Gson();
		List<FoodList>list=gson.fromJson(jsondata, type);
		return list;
	}
	/**
	 * 预订订单解析
	 * @param jsondata
	 * @return
	 */
	public static Book BookFromJson(String jsondata){
		Type type=new TypeToken<Book>(){}.getType();
		Gson gson=new Gson();
		Book book=gson.fromJson(jsondata, type);
		return book;
	}
	/**
	 * 
	 * @param jsondata
	 * @return
	 */
	public static List<Book> BookListFromJson(String jsondata){
		Type type=new TypeToken<List<Book>>(){}.getType();
		Gson gson=new Gson();
		List<Book>list=gson.fromJson(jsondata, type);
		return list;
	}
	/**
	 * 消息实体解析
	 * @param jsondata
	 * @return
	 */
	public static NotificationBean NotificationBeanFromJson(String jsondata){
		Type type=new TypeToken<NotificationBean>(){}.getType();
		Gson gson=new Gson();
		NotificationBean noti=gson.fromJson(jsondata, type);
		return noti;
	}
	
	public static IncomeMsg IncomeMsgFromJson(String jsondata){
		Type type=new TypeToken<IncomeMsg>(){}.getType();
		Gson gson=new Gson();
		IncomeMsg imsg=gson.fromJson(jsondata, type);
		return imsg;
	}
}
